Looking at distribution shapes

This compares violin plots and boxplots from seaborn, and stem_graphic from stemgraphic.


In [1]:
import matplotlib.pyplot as plt
from stemgraphic.num import stem_graphic
import numpy as np
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")

setup


In [2]:
height = 5

In [3]:
np.random.seed(42)

# a few distributions, 500 values from each
normal_pop = np.random.normal(loc=500, scale=100, size=500).round(2)  # mean, std dev, number in population
uniform_pop = np.random.uniform(low=0, high=1000, size=500).round(2)   # min, max, number in population
exponential_pop = np.random.exponential(scale=100.0, size=500).round(2)   # scale, number in population
triangular_pop = np.random.triangular(left=0.0, mode=400, right=1000, size=500).round(2)

Normal distribution


In [4]:
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(3*(height+1), height))
sns.violinplot(normal_pop, orient='v', ax=ax1)
sns.boxplot(normal_pop, orient='v', ax=ax2)
stem_graphic(normal_pop, ax=ax3);



In [5]:
stem_graphic(normal_pop);



In [6]:
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(3*(height+1), height))
sns.violinplot(uniform_pop, orient='v', ax=ax1)
sns.boxplot(uniform_pop, orient='v', ax=ax2)
stem_graphic(uniform_pop, ax=ax3);



In [7]:
stem_graphic(uniform_pop);



In [8]:
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(3*(height+1), height))
sns.violinplot(exponential_pop, orient='v', ax=ax1)
sns.boxplot(exponential_pop, orient='v', ax=ax2)
stem_graphic(exponential_pop, ax=ax3);



In [9]:
stem_graphic(exponential_pop);



In [10]:
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(3*(height+1), height))
sns.violinplot(triangular_pop, orient='v', ax=ax1)
sns.boxplot(triangular_pop, orient='v', ax=ax2)
stem_graphic(triangular_pop, ax=ax3);



In [11]:
stem_graphic(triangular_pop);



In [ ]: